home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / fft.lst < prev    next >
Encoding:
File List  |  1991-08-11  |  11.2 KB  |  253 lines

  1.  
  2. Motorola DSP56000 Macro Cross Assembler  Version 2.02  91-08-11  13:44:22  fft.asm  Page 1
  3.  
  4.  
  5.  
  6. 1                                  page    132,63,1,1
  7. 2                                  opt     rc
  8. 4      
  9. 5                        ;***************************************************************
  10. 6                        ;* FFT.ASM -- FFT transform, periodogram calculation and       *
  11. 7                        ;*            main control loop                             *
  12. 8                        ;*                                                       *
  13. 9                        ;* Provides main control loop of the FFT based periodogram     *
  14. 10                       ;* spectrum analyzer.                                      *
  15. 11                       ;*                                                       *
  16. 12                       ;* Periodogram calculation is based on the book:               *
  17. 13                       ;*      Oppenheim, A, Shafer, R.:                           *
  18. 14                       ;*      "Digital Signal Processing",                        *
  19. 15                       ;*      Prentice-Hall, 1975                                *
  20. 16                       ;*                                                       *
  21. 17                       ;* This module uses registers as follows:                     *
  22. 18                       ;*  r0 -                                                  *
  23. 19                       ;*  r1 -                                                  *
  24. 20                       ;*  r4 -                                                  *
  25. 21                       ;*  r5 -                                                  *
  26. 22                       ;*  r6 -                                                  *
  27. 23                       ;*                                                       *
  28. 24                       ;* Copyright (C) 1991 by Alef Null. All rights reserved.       *
  29. 25                       ;* Author(s): Jarkko Vuori, OH2LNS                           *
  30. 26                       ;* Modification(s):                                        *
  31. 27                       ;***************************************************************
  32. 28     
  33. 236    
  34. 237                                section FFT
  35. 238                                xdef    ssi_ini,fft_i
  36. 239                                xdef    m_loop
  37. 240                                xref    m_cra,m_crb,m_tde,m_sr,m_tx
  38. 241    
  39. 242       P:0000                   org     p:
  40. 243    
  41. 568    
  42. 569       00000400       points    equ     1024
  43. 570    
  44. 571                      ; multiply p:(r0) (data) by p:(r1) (window) and
  45. 572                      ; put the result to x/y:(r2) (destination)
  46. 573                      winblk    macro   dest
  47. 574  m                             move    p:(r0)+,x0
  48. 575  m                             move    p:(r1)+,x1
  49. 576  m                             mpyr    x0,x1,a
  50. 577  m                             do      #points-1,_endloop
  51. 578  m                             move    p:(r0)+,x0
  52. 579  m                             move    p:(r1)+,x1
  53. 580  m                             mpyr    x0,x1,a   a,dest:(r2)+
  54. 581  m                   _endloop
  55. 582  m                             move    a,dest:(r2)+
  56. 583  m                             endm
  57. 584    
  58. 585    
  59. 586                      ;****************************
  60. 587                      ;*    SSI initialization    *
  61. 588                      ;****************************
  62. 589                      ssi_ini
  63.  
  64.  
  65. Motorola DSP56000 Macro Cross Assembler  Version 2.02  91-08-11  13:44:22  fft.asm  Page 2
  66. FFT transform and periodogram calculation
  67.  
  68.  
  69. 590                      ; initialize SSI,
  70. 591                                IF      !0
  71. 592       P:0000 08F4AC            movep             #$4000,x:m_cra ; 16 bit word
  72.                  004000
  73. 593       P:0002 08F4AD            movep             #$f200,x:m_crb ; syncronous,word frame,ext clk
  74.                  00F200
  75. 594                                ELSE
  76. 597                                ENDIF
  77. 598    
  78. 599       P:0004 00000C            rts
  79. 600    
  80. 601    
  81. 602                      ;****************************
  82. 603                      ;*        ADC & FFT        *
  83. 604                      ;*      initialization     *
  84. 605                      ;****************************
  85. 606                      fft_i
  86. 607                      ; program the A/D & D/A converter chip (TLC32044, master clock is 5.184MHz)
  87. 608                      ; disable A/D high-pass filter, disable loopback, disable AUX IN,
  88. 609                      ; select syncronous mode, select input span 3Vpp, insert sinx/x correction
  89. 610                      ; lowpass cutoff frequency at   3600Hz -> TA  =  9 (SCF = 288kHz)
  90. 611                      ; sampling frequency is         8000Hz -> TB  = 36
  91. 612                      ; unit sampling correction time  0.4uS -> TA' =  2
  92. 613                                pgmtlc  %10101001,9,2,36
  93. 641    
  94. 642                      ; initialize input sample pointers
  95. 643       P:0029 67F400            move              #samples,r7
  96.                  000000
  97. 644       P:002B 05F427            move              #points-1,m7
  98.                  0003FF
  99. 645    
  100. 646                      ; and FFT average counter
  101. 647       P:002D 07F08E            move              p:NN2,a
  102.                  000000
  103. 648       P:002F 5E0000            move                          a,y:<count
  104. 649       P:0030 00000C            rts
  105. 650    
  106. 651    
  107. 652                      ;****************************
  108. 653                      ;*        Main Loop        *
  109. 654                      ;****************************
  110. 655       P:0031 000086  loop      wait
  111. 656                      m_loop
  112. 657    
  113. 658                      ; check if one block converted
  114. 659       P:0032 44F400            move              #>samples,x0
  115.                  000000
  116. 660       P:0034 22EE00            move              r7,a
  117. 661       P:0035 209045            cmp     x0,a      x0,r0
  118. 662       P:0036 0E2000            jne     <loop
  119. 663    
  120. 664                      ; yes, multiply samples with window
  121. 665       P:0037 61F400            move              #window,r1
  122.                  000000
  123. 666       P:0039 62F400            move              #data,r2
  124.                  000000
  125. 667       P:003B 05F421            move              #-1,m1
  126.  
  127.  
  128. Motorola DSP56000 Macro Cross Assembler  Version 2.02  91-08-11  13:44:22  fft.asm  Page 3
  129. FFT transform and periodogram calculation
  130.  
  131.  
  132.                  FFFFFF
  133. 668       P:003D 0462A1            move              m1,m2
  134. 669    
  135. 670       P:003E 0B0003            bchg    #blksel,x:<status
  136. 671       P:003F 0E0000            jcc     <fft1
  137. 672                                winblk  x
  138. 682       P:0049 0C0000            jmp     <loop
  139. 683                      fft1      winblk  y
  140. 693    
  141. 694                      ; real and imaginary banks filled, so transform data
  142. 695                      ; 129000 cycles, 6.22 mS
  143. 696                                fftr2a  points,data,coef
  144. 783    
  145. 784                      ; extract, scale and accumulate data
  146. 785                      ; select accumulator
  147. 786       P:007D 60F400            move              #accb,r0
  148.                  000000
  149. 787       P:007F 0A00A4            jset    #accsel,x:<status,fft2
  150.                  000083
  151. 788       P:0081 60F400            move              #acca,r0
  152.                  000000
  153. 789                      fft2
  154. 790    
  155. 791                      ; extract and take square
  156. 792                      ;   1/4[(Zr(k)+Zr(N-k))^2 + (Zi(k)-Zi(N-k))^2 + Zi(N-k)+Zi(k))^2 + Zr(N-k)-Zr(k))^2]
  157. 793                      ; = 1/2[Zr(k)^2 + Zi(k)^2 + Zr(N-k)^2 + Zi(N-k)^2]
  158. 794       P:0083 61F400            move              #data,r1
  159.                  000000
  160. 795       P:0085 62F400            move              #data+points-1,r2
  161.                  000000
  162. 796       P:0087 71F400            move              #points/2,n1
  163.                  000200
  164. 797       P:0089 233A00            move              n1,n2
  165. 798       P:008A 0500A1            move              #0,m1
  166. 799       P:008B 0462A1            move              m1,m2
  167. 800    
  168. 801       P:008C 44E100            move              x:(r1),x0
  169. 802       P:008D 060082            do      #points/2,endcopy ; k = 0..N/2
  170.                  000096
  171. 803       P:008F 4EC980            mpy     x0,x0,a               y:(r1)+n1,y0 ; Zr(k)^2 + Zi(k)^2
  172. 804       P:0090 44E292            mac     y0,y0,a   x:(r2),x0   ; Zr(N-k)^2 + Zi(N-k)^2
  173. 805       P:0091 4EC282            mac     x0,x0,a               y:(r2)-n2,y0
  174. 806       P:0092 200092            mac     y0,y0,a
  175. 807       P:0093 07E084            move              p:(r0),x0   ; add to result
  176. 808       P:0094 200040            add     x0,a
  177. 809       P:0095 44E111            rnd     a         x:(r1),x0
  178. 810       P:0096 07588E            move              a,p:(r0)+
  179. 811                      endcopy
  180. 812    
  181. 813                      ; check if enought integrated
  182. 814       P:0097 5E8000            move                          y:<count,a
  183. 815       P:0098 44F400            move              #>1,x0
  184.                  000001
  185. 816       P:009A 44F444            sub     x0,a      #>accb,x0
  186.                  000000
  187. 817       P:009C 5E0000            move                          a,y:<count
  188. 818       P:009D 0E2000            jne     <loop
  189.  
  190.  
  191. Motorola DSP56000 Macro Cross Assembler  Version 2.02  91-08-11  13:44:22  fft.asm  Page 4
  192. FFT transform and periodogram calculation
  193.  
  194.  
  195. 819    
  196. 820                      ; yes, send result to host
  197. 821       P:009E 07F08E            move              p:NN2,a
  198.                  000000
  199. 822       P:00A0 5E0000            move                          a,y:<count
  200. 823    
  201. 824       P:00A1 0A00A4            jset    #accsel,x:<status,fft4
  202.                  0000A5
  203. 825       P:00A3 44F400            move              #>acca,x0
  204.                  000000
  205. 826       P:00A5 56F400  fft4      move              #>points/2,a
  206.                  000200
  207. 827       P:00A7 200040            add     x0,a
  208. 828       P:00A8 21C500            move              a,x1
  209. 829    
  210. 830       P:00A9 0B7002            bchg    #$2,x:m_pcd
  211.                  000000
  212. 831       P:00AB 0D0000            jsr     <putblk
  213. 832    
  214. 833                      ; change to new accumulator, and clear it
  215. 834       P:00AC 60F413            clr     a         #acca,r0
  216.                  000000
  217. 835       P:00AE 0B0004            bchg    #accsel,x:<status
  218. 836       P:00AF 0E8000            jcs     <fft5
  219. 837       P:00B0 60F400            move              #accb,r0
  220.                  000000
  221. 838       P:00B2 060082  fft5      do      #points/2,_endloop
  222.                  0000B4
  223. 839       P:00B4 07588E            move              a,p:(r0)+
  224. 840                      _endloop
  225. 841    
  226. 842       P:00B5 0C0000            jmp     <loop
  227. 843    
  228. 844    
  229. 845                      ;****************************
  230. 846                      ;*       DATA - AREA       *
  231. 847                      ;****************************
  232. 848    
  233. 849       Y:0000                   org     y:
  234. 850    
  235. 851       Y:0000 000000  count     ds      1
  236. 852    
  237. 853                                endsec
  238. 854    
  239. 855                                end
  240. 0    Errors
  241. 0    Warnings
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.